package com.wxp.demo09.screen;

import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo09.R;
import com.wxp.demo09.util.LogUtils;
import com.wxp.demo09.util.ToastUtil;

/**
 * 3.2 屏幕改变方向不重新加载
 */
public class ChangeDirectionActivity extends AppCompatActivity {

    private TextView tv_monitor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_change_direction);
        this.setTitle("3.2 屏幕改变方向不重新加载");

        tv_monitor = findViewById(R.id.tv_monitor);
        LogUtils.debug("onCreate");
        ToastUtil.show(this, "onCreate");
    }

    /**
     * 在配置项变更时触发。比如屏幕方向发生变更等等
     *
     * @param newConfig 配置对象
     */
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //判断方向
        switch (newConfig.orientation) {
            case Configuration.ORIENTATION_PORTRAIT:
                tv_monitor.setText("当前屏幕为竖屏方向");
                break;
            case Configuration.ORIENTATION_LANDSCAPE:
                tv_monitor.setText("当前屏幕为横屏方向");
                break;
            default:
                break;
        }
    }

}